from sklearn.decomposition import PCA
from sklearn.datasets import load_iris

iris = load_iris()
pca = PCA(n_components=2)
X_pca = pca.fit_transform(iris.data)
print("方差贡献率:", pca.explained_variance_ratio)
import numpy as np
from statsmodels.stats.power import tt_ind_solve_power

# 计算样本量
effect_size = (0.15 - 0.10) / np.sqrt(0.10*(1-0.10))  # Cohen's h
n = tt_ind_solve_power(effect_size=effect_size, alpha=0.05, power=0.8)

# 计算功效
power = tt_ind_solve_power(effect_size=effect_size, alpha=0.05, nobs1=500)
print(power)
